package work;

import java.util.Scanner;

/*
4 求s=a+aa+aaa+aaaa+aa...a的值，其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加)，几个数相,加的数是谁,加由键盘控制
 */
public class Work04 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要计算的数字：");
        int number = scanner.nextInt();
        System.out.println("请输入次数：");
        int counts = scanner.nextInt();

        print(number,counts);
        int sum = calculateAdd(number,counts);
        System.out.println("结果为"+sum);
    }

    static void print(int number,int counts){
        int temp = 0;
        for (int i = 0; i < counts; i++) {
            temp = temp*10+number;
            if(temp==number){
                System.out.print(temp);
            }else {
                System.out.print("+"+temp);
            }
        }
        System.out.println();
    }
    static int calculateAdd(int number,int counts){
        int sum = 0;
        int temp = 0;
        for (int i = 0; i < counts; i++) {
            temp = temp*10+number;
            sum+=temp;
        }
        return sum;
    }
}
